<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>新春贺卡</title>
  </head>

  <body>
    <script>
      let flag = 0
      function commit() {
        if (flag == 0) {
          flag = 1
          // 模拟request API
          setTimeout(() => {
            flag = 0
            console.log('你好你好你好')
          }, 2000)
        }
      }
      commit()
      commit()

      function promiseTest() {
        let firstPromise = new Promise((resolve, reject) => {
          // 异步处理
          setTimeout(() => {
            resolve()
            console.log('resolve')
          }, 1000)
          // 处理结束后 调用 resolve 或者 reject
        })
          .then(() => {
            return new Promise((resolve, reject) => {
              setTimeout(() => {
                reject()
                console.log('reject')
              }, 1000)
            })
          })
          .catch(() => {
            console.log('catch')
          })
      }
      promiseTest()
    </script>
  </body>
</html>
